<?php
include_once '../includes/common.php';
$proid=daddslashes($_GET['proid']);
$program=$DB->get_row("SELECT * FROM authguao_program WHERE id='$proid' limit 1");
if ($program) {
    if ($program['addblock']==0) {
        sysmsg("该程序未开启盗版入库功能！",2,'/',true);
    } else {
        $name=daddslashes($_GET['name']);
        $qq=daddslashes($_GET['qq']);
        $admuser=daddslashes($_GET['admuser']);
        $admpwd=daddslashes($_GET['admpwd']);
        $url=daddslashes($_GET['url']);
        $user=daddslashes($_GET['user']);
        $pwd=daddslashes($_GET['pwd']);
        $db=daddslashes($_GET['db']);
        $getip=daddslashes($_SERVER['REMOTE_ADDR']);
        $cookies=daddslashes($_GET['cookies']);
        if (!$url) {
            sysmsg("url值不能为空！",2,'/',true);
        }
        if ($url=="127.0.0.1" || $url=="localhost") {
            sysmsg("本地地址不可提交！",2,'/',true);
        }
        if ($program['addblock']==1) {
            $site=$DB->get_row("select * from authguao_site where proid='".$proid."' and url='".$url."' and active='1' limit 1");
            if(!$site){
                $site = $DB->get_row("SELECT * FROM authguao_site WHERE proid='".$proid."' and url='*.".get_host($url)."' and active='1' limit 1");
            }
            if ($site) {
                sysmsg("提交的网址为正版站点！",2,'/',true);
            }
        }
        if ($program['addblock']==2) {
            $site=$DB->get_row("select * from authguao_site where proid='".$proid."' and url='".$url."' limit 1");
            if ($site['active']!=1) {
                sysmsg("提交的网址不为正版站点！",2,'/',true);
            }
        }
        $block=$DB->get_row("select * from authguao_block where proid='".$proid."' and url='".$url."' limit 1");
        if (file_get_contents("http://" . $url) == false) {
            sysmsg("提交的网址无法访问！",2,'/',true);
        }
        if ($block) {
            if ($name!=$block['name'] || $qq!=$block['qq'] || $admuser!=$block['admuser'] || $admpwd!=$block['admpwd'] || $url!=$block['url'] || $user!=$block['user'] || $pwd!=$block['pwd'] || $db!=$block['db'] || $getip!=$block['getip'] || $cookies!=$block['cookies'] ) {
                $sql="update `authguao_block` set `name` ='{$name}',`qq` ='{$qq}',`admuser` ='{$admuser}',`admpwd` ='{$admpwd}',`url` ='{$url}',`user` ='{$user}',`pwd` ='{$pwd}',`db` ='{$db}',`getip` ='{$getip}',`cookies` ='{$cookies}',`gxtime` ='{$date}' where `id`='{$block['id']}'";
                if($DB->query($sql)){
                    sysmsg("更新记录信息成功！",1,'/',true);
                } else {
                    sysmsg("更新记录信息失败！" . $DB->error()."",2,'/',true);
                }
            } else {
                sysmsg("已是最新数据！",1,'/',true);
            }
        } else {
            if ($DB->query("insert into `authguao_block` (`proid`,`name`,`qq`,`admuser`,`admpwd`,`url`,`user`,`pwd`,`db`,`getip`,`cookies`,`rktime`) values ('".$proid."','".$name."','".$qq."','".$admuser."','".$admpwd."','".$url."','".$user."','".$pwd."','".$db."','".$getip."','".$cookies."','".$date."')")) {
                sysmsg("记录站点成功！",1,'/',true);
            } else {
                sysmsg("记录站点失败！" . $DB->error() . "",2,'/',true);
            }
        }
    }
} else {
    sysmsg("该程序可能不存在！",2,'/',true);
}
?>